var gulp = require('gulp');
var uglify = require('gulp-uglify');
var minCss = require('gulp-minify-css');
var del = require('del');
var pipe = require('gulp-pipe');
var concat = require('gulp-concat');

gulp.task('del', function() {
    return del('./static').then(function(paths) {
        if (paths.length) {
            console.log('删除文件和文件夹:\n', paths.join('\n'));
        }
    });
});
gulp.task('css', function() {
    var arr = [gulp.src('./dev/css/*.css'), concat('markdown.css'), minCss(), gulp.dest('./static/css')];
    return pipe(arr);
});
gulp.task('js', function() {
    var jsSrcArr = ['./dev/js/marked.js', './dev/js/highlight.pack.js', './dev/js/tools.js'];
    var arr = [gulp.src(jsSrcArr), concat('markdown.js'), uglify({
        mangle: true,
        output: {
            ascii_only: true
        }
    }), gulp.dest('./static/js')];
    return pipe(arr);
});
gulp.task('watch', function() {
    var watcher = gulp.watch(['./dev/css/**/*.css', './dev/js/**/*.js'], ['css', 'js']);
    watcher.on('change', function(event) {
        console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
    });
});
gulp.task('default', ['del'], function() {
    gulp.start('css', 'js', 'watch');
});